package com.macrog.rabbitmq.publish;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.macrog.rabbitmq.utils.ConnectionFactoryUtil;

import java.io.IOException;

/**
 * Created by Administrator on 2018/9/1.
 */
public class Send {

    private static final String EXCHANGE_NAME = "publishExchange";

    public static void main(String[] args) throws IOException {
        Connection connection = ConnectionFactoryUtil.getConnection();

        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");
        String message = "通过发布订阅模式发送的消息";
        //发布订阅模式，消息是发送到交换机上，交换机是没有保存功能的，如果没有消费者，消息会丢弃
        channel.basicPublish(EXCHANGE_NAME,"",null,message.getBytes());

        ConnectionFactoryUtil.release(connection,channel);

    }
}
